package implementations;

import java.util.ArrayList;

import com.sun.org.apache.xpath.internal.operations.Bool;

import interfaces.IPoint;
import interfaces.IShip;

public class ShipImpl implements IShip {

	private IPoint mainPoint;
	private ArrayList<IPoint> points;
	private ArrayList<Boolean> hits;
	private boolean alive;
	private boolean planted;

	public ShipImpl(ArrayList<IPoint> thePoints) {
		alive = true;
		planted = false;
		points = thePoints;
		hits=new ArrayList<>();
		mainPoint = points.get(0);
		for (int i = 0; i < points.size(); i++)
			hits.add(false);
	}

	@Override
	public void rotateShip() {
		// TODO Auto-generated method stub

	}

	@Override
	public void recalculatePoints() {

		IPoint origin = points.get(0);
		for (int i = 1; i < points.size(); i++) {
			IPoint iPoint = points.get(i);
			points.set(i, new PointImpl(mainPoint.getX() + iPoint.getX()-origin.getX(),
					mainPoint.getY() + iPoint.getY()-origin.getY()));
		}
		points.set(0, mainPoint);
	}

	@Override
	public void setMainPoint(IPoint mPoint) {
			mainPoint = mPoint;
			recalculatePoints();

	}

	@Override
	public IPoint getMainPoint() {
		return mainPoint;
	}

	@Override
	public ArrayList<IPoint> getPoints() {
		return points;
	}

	@Override
	public ArrayList<Boolean> getHits() {
		return hits;
	}

	@Override
	public boolean isAlive() {
		for(boolean hit:hits)
		{
			if(hit==false)
				return true;
			
		}
		return false;
	}

	@Override
	public boolean isPlanted() {
		return planted;
	}

	public void setIsPlanted(boolean ok) {
		planted=ok;
	}
	
}
